package org.aspire.math.geom.event;

/******************************************************************************
 * An event triggered by the change in the width and/or height of the dimension
 * data. This event contains the source of change in data and the amount of
 * change in one or both stored in floating point precision. The change can
 * also be retrieved in integer precision.
 * 
 * @author JPACarabuena
 *****************************************************************************/
public class DimensionEvent {

	// ========================================================================
	// Constants
	// ========================================================================
	
	/**
	 * The source of change is the width data.
	 */
	public static int SRC_WIDTH 	= 1;
	
	/**
	 * The source of change is the height data.
	 */
	public static int SRC_HEIGHT 	= 2;
	
	/**
	 * The source of change is both the width and height data.
	 */
	public static int SRC_BOTH		= 3;

	// ========================================================================
	// Static Methods
	// ========================================================================
		
	// ========================================================================
	// Fields
	// ========================================================================
	
	/**
	 * Holds the value for the source of data change. There are three different
	 * source of change in dimension: Width, Height, and Both.
	 */
	protected int source;
	
	/**
	 * The change in value of the width in floating point precision. A positive
	 * value denotes an increase in the width while a negative value represents
	 * a decrease.
	 */
	protected float deltaWidth;
	
	/**
	 * The change in value of the height in floating point precision. A 
	 * positive value denotes an increase in the height while a negative value
	 * represents a decrease.
	 */
	protected float deltaHeight;
	
	// ========================================================================
	// Constructors
	// ========================================================================
	
	/**
	 * Creates a new dimension change event with the specified source of change
	 * and the floating point value of the changes in width and/or height.
	 * 
	 * @param source	the source of change.
	 * @param deltaWidth	the change in width.
	 * @param deltaHeight	the change in height.
	 */
	public DimensionEvent(int source, float deltaWidth,
			float deltaHeight) {
		this.source = source;
		this.deltaWidth = deltaWidth;
		this.deltaHeight = deltaHeight;
	}
	
	// ========================================================================
	// Getters & Setters
	// ========================================================================
	
	/**************************************************************************
	 * Checks the source of change in the dimension data.
	 * 
	 * @return	The integer flag for the source. 
	 *************************************************************************/
	public int getSource() {
		return this.source;
	}
	
	/**************************************************************************
	 * Checks the change in width that triggered the event in floating point
	 * precision.
	 * 
	 * @return	The change in width.
	 *************************************************************************/
	public float getWidthChange() {
		return this.deltaWidth;
	}
	
	/**************************************************************************
	 * Checks the change in width that triggered the event in integer
	 * precision.
	 * 
	 * @return	The change in width.
	 *************************************************************************/
	public int getWidthChangeInt() {
		return Math.round(this.deltaWidth);
	}
	
	/**************************************************************************
	 * Checks the change in height that triggered the event in floating point
	 * precision.
	 * 
	 * @return	The change in height.
	 *************************************************************************/
	public float getHeightChange() {
		return this.deltaHeight;
	}
	
	/**************************************************************************
	 * Checks the change in height that triggered the event in integer
	 * precision
	 * 
	 * @return	The change in height.
	 *************************************************************************/
	public int getHeightChangeInt() {
		return Math.round(this.deltaHeight);
	}
	
	// ========================================================================
	// Override Methods
	// ========================================================================
	
	// ========================================================================
	// Methods
	// ========================================================================
	
	/**************************************************************************
	 * Checks if the change happened in the width data only.
	 * 
	 * @return Whether or not the change is triggered by the width data only.
	 *************************************************************************/
	public boolean isChangeInWidthOnly() {
		return (this.source == DimensionEvent.SRC_WIDTH);
	}
	
	/**************************************************************************
	 * Checks if the change happened in the height data only.
	 * 
	 * @return Whether or not the change is triggered by the height data only.
	 *************************************************************************/
	public boolean isChangeInHeightOnly() {
		return (this.source == DimensionEvent.SRC_HEIGHT);
	}
	
	/**************************************************************************
	 * Checks if the change happened in both the width and height data.
	 * 
	 * @return 
	 * 		Whether or not the change is triggered by both the width and
	 * 		height data.
	 *************************************************************************/
	public boolean isChangeBoth() {
		return (this.source == DimensionEvent.SRC_BOTH);
	}
	
	// ========================================================================
	// Inner & Anonymous Classes
	// ========================================================================
}